package com.ellricky.newtv.dialog

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.DialogFragment
import com.ellricky.newtv.R
import com.ellricky.newtv.bean.TvCourseEndDate
import kotlinx.android.synthetic.main.dialog_class_add.*
import kotlinx.android.synthetic.main.dialog_class_add.iv_finish
import kotlinx.android.synthetic.main.dialog_class_add.tv_confirm
import kotlinx.android.synthetic.main.dialog_vip_hint.*

class VipHitFragment(val endDate: Int) : DialogFragment() {

    private var listener: OnVipDialogListener? = null

    interface OnVipDialogListener {
        fun onContact()
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.dialog_vip_hint, container, false)
    }

    override fun onStart() {
        super.onStart()
        val window = dialog?.window
        window?.also {
            val windowAttributes = it.attributes.apply {
                dimAmount = 0.4f
            }
            it.attributes = windowAttributes

            val width = resources.getDimensionPixelSize(R.dimen.dp_280)
            val height = resources.getDimensionPixelSize(R.dimen.dp_230)
            it.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
            it.setLayout(width, height)
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        tv_days.text = "${endDate}天"
        iv_finish.setOnClickListener { dismissAllowingStateLoss() }
        tv_confirm.setOnClickListener {
            listener?.onContact()
            dismissAllowingStateLoss()
        }
    }

    fun setOnVipDialogListener(listener: OnVipDialogListener) {
        this.listener = listener
    }
}